#include "dominion.h"
#include "dominion_helpers.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char *argv[])
{
    struct gameState* game;
    int *bonus = malloc(sizeof(int));
    int *carddeck;
    int deck[10];
    int temphand[10];
    int i, players, which_player;
    int treasure_count = 0;

    srand(time(NULL));

    for (i=0;i<10;i++) {
        //randomize cards in the deck
        deck[i] = rand() % 26;
    }

    //Set those randomized cards to the deck
    carddeck = kingdomCards(deck[0], deck[1], deck[2], deck[3], deck[4], deck[5], deck[6], deck[7], deck[8], deck[9]);

    //Count the number of treasure cards in the deck
    for (i=0;i<10;i++) {
        if (deck[i] == copper || deck[i] == silver || deck[i] == gold)
            treasure_count++;
    }

    //Standard game initialization
    game = newGame();

    //Set the game state to this number of players
    game->numPlayers = 2;
    initializeGame(players, carddeck, 24, game);

    //game->deckCount = 0;

    //Call adventure with randomized deck that will be played (10 cards w/ random cards)
    adventure_call(1, game, treasure_count, temphand);

    //Tests
    //Next player should be number two
    if (game->whoseTurn != 2) {
	   printf("Failure returning correct player\n");
	}
    else {
        printf("Success returning correct player\n");
	}

    //If the deck had only 1 treasure card, the deck should now only have that card
    if (treasure_count == 1)
        if (game->deckCount[which_player] != 1)
	   printf("Failure getting correct deck count");

    //Unless the first two cards were treasure cards there should be discarded cards now
    if ((deck[0] == copper || deck[0] == silver || deck[0] == gold) && (deck[1] == copper || deck[1] == silver || deck[1] == gold))
        printf("No discard in this test\n");
    else
        if (game->discardCount[which_player] == 0)
	   printf("Failure increasing discard count\n");

    //To increase coverage we should run this test a second time setting the players deckCount to 0 triggering a shuffle

    free(bonus);
    return 0;
}
